package logic

import (
	"context"
	"fmt"
	"shoppings/model/redis"

	"shoppings/shoprpc/internal/svc"
	"shoppings/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LikeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLikeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeListLogic {
	return &LikeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LikeListLogic) LikeList(in *shoprpc.LikeListRequest) (*shoprpc.LikeListResponse, error) {
	// todo: add your logic here and delete this line
	scores := redis.Rdb.ZRangeWithScores("like", 0, 9)
	fmt.Println(scores)
	var shop []*shoprpc.Like
	for _, z := range scores.Val() {
		like := shoprpc.Like{
			Name: z.Member.(string),
			Like: int64(z.Score),
		}
		shop = append(shop, &like)
	}
	fmt.Println(shop)
	return &shoprpc.LikeListResponse{Like: shop}, nil
}
